package com.ruipengkj.component;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.TexturePaint;

import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.factory.ImageFactory;

public class RPJLabelTitle extends JLabel {

	private static final long serialVersionUID = 1L;
	
	private TexturePaint paint = Util.createTexturePaint(ImageFactory.loadImage(ImageFactory.LAB_TITLE_BG).getImage());
	private Image backgroundLeftImage = ImageFactory.loadImage(ImageFactory.LAB_TITLE_BG_LEFT).getImage();
	private Image backgroundRightImage = ImageFactory.loadImage(ImageFactory.LAB_TITLE_BG_RIGHT).getImage();
	private Icon icon = ImageFactory.loadImage(ImageFactory.LAB_TITLE_ICON);
	
	public RPJLabelTitle(String text){
		super(text+" ");
		this.setIcon(icon);
		setForeground(Color.WHITE);
		setFont(Util.FONT_13_BOLD);
		this.setHorizontalAlignment(JButton.RIGHT);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
			//鼠标滑过
			g2d.setPaint(paint);
			g2d.fillRect(4, 0, this.getWidth()-8, this.getHeight());
			// draw left image.
			g2d.drawImage(backgroundLeftImage, 0, 0, null);
			// draw right image.
			int x = this.getWidth() - backgroundRightImage.getWidth(null);
			int y = 0;
			g2d.drawImage(backgroundRightImage, x, y, null);
		super.paintComponent(g);
	}
}
